package br.ufmg.dcc.vod.remoteworkers.scheduler.server;

import java.util.Set;

import br.edu.ufcg.lsd.commune.ApplicationServer;
import br.edu.ufcg.lsd.commune.container.ContainerContext;
import br.edu.ufcg.lsd.commune.container.control.ApplicationServerManager;
import br.edu.ufcg.lsd.commune.identification.ServiceID;
import br.edu.ufcg.lsd.commune.network.xmpp.CommuneNetworkException;
import br.edu.ufcg.lsd.commune.processor.ProcessorStartException;
import br.ufmg.dcc.vod.remoteworkers.scheduler.Scheduler;
import br.ufmg.dcc.vod.remoteworkers.scheduler.SchedulerListener;

public class SchedulerApplicationServer extends ApplicationServer {

	public static final String SERVICE_NAME = "SCHEDULER_SERVICE";

	public SchedulerApplicationServer(ContainerContext context) throws CommuneNetworkException,	ProcessorStartException {
		super(SERVICE_NAME, context);
	}

	@Override
	protected ApplicationServerManager createApplicationManager() {
		SchedulerApplicationManager schedulerApplicationManager = new SchedulerApplicationManager();
		return schedulerApplicationManager;
	}
	
	public void initScheduler(SchedulerListener listener, Set<ServiceID> sids) {
		Scheduler scheduler = (Scheduler) getContainer().getObjectRepository().get(Scheduler.OBJECT_NAME).getObject();
		
		listener.setScheduler(scheduler);
		scheduler.setListener(listener);
		scheduler.setProcessors(sids);
	}
}
